agr <- d %>%
group_by(Task) %>%
summarize(MeanAccuracy = mean(Accuracy),
SD = sd(Accuracy))
print(agr)
## # A tibble: 3 × 3
## Task MeanAccuracy SD
## <chr> <dbl> <dbl>
## 1 Animacy 0.965 0.183
## 2 Concrete 0.831 0.375
## 3 Valence 0.936 0.244
agr <- d %>%
group_by(Task) %>%
reframe(MeanAccuracy = mean(Accuracy),
CILow = ci.low(Accuracy),
CIHigh = ci.high(Accuracy)) %>%
mutate(YMin = MeanAccuracy - CILow,
YMax = MeanAccuracy + CIHigh)
# View(agr)
dodge = position_dodge(.9)
ggplot(data=agr, aes(x=Task,y=MeanAccuracy, fill = Task)) +
geom_bar(position=dodge,stat="identity") +
geom_errorbar(aes(ymin=YMin,ymax=YMax),width=.25,position=position_dodge(0.9))
# theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
# guides(fill = "none")
agr <- d %>%
group_by(Word,Task,Category) %>%
reframe(MeanAccuracy = mean(Accuracy),
CILow = ci.low(Accuracy),
CIHigh = ci.high(Accuracy)) %>%
mutate(YMin = MeanAccuracy - CILow,
YMax = MeanAccuracy + CIHigh)
ggplot(agr, aes(x=Task, y=MeanAccuracy,fill=Category)) +
geom_violin(trim=FALSE,alpha=.4) +
geom_jitter(shape=16, position=position_jitter(0.2))
# guides(fill = "none")
agr <- d %>%
filter(Task == "Concrete") %>%
mutate(Response.n = as.numeric(factor(Response, levels = c("abstract", "concrete"))) - 1) %>%
group_by(ConcValCombo,Category) %>%
summarize(PropConcrete = mean(Response.n),
CILow = ci.low(Response.n),
CIHigh = ci.high(Response.n)) %>%
mutate(YMin = PropConcrete - CILow,
YMax = PropConcrete + CIHigh)
## `summarise()` has grouped output by 'ConcValCombo'. You can override using the
## `.groups` argument.
dodge = position_dodge(.9)
ggplot(data=agr, aes(x=Category,y=PropConcrete,fill=ConcValCombo)) +
geom_bar(position=dodge,stat="identity") +
# facet_wrap(~Version) +
geom_errorbar(aes(ymin=YMin,ymax=YMax),width=.25,position=position_dodge(0.9))
# theme(axis.text.x = element_text(angle = 45, hjust = 1))
agr <- d %>%
filter(Task == "Concrete") %>%
mutate(Response.n = as.numeric(factor(Response, levels = c("abstract", "concrete"))) - 1) %>%
group_by(Word,ConcValCombo) %>%
summarize(PropConcrete = mean(Response.n),
MeanReactionTime = mean(ReactionTime))
## `summarise()` has grouped output by 'Word'. You can override using the
## `.groups` argument.
ggplot(agr, aes(x = MeanReactionTime, y = PropConcrete)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "red") +
geom_text(aes(label = Word, color = ConcValCombo), vjust = -0.5, hjust = 1.5)
## `geom_smooth()` using formula = 'y ~ x'
# geom_text_repel(aes(label = Word, color = ConcValCombo),
# vjust = -0.5, hjust = 1.5) +
# scale_fill_manual(values=cbPalette) +
# scale_color_manual(values=cbPalette)
agr <- d %>%
filter(Task == "Valence") %>%
mutate(Response.n = as.numeric(factor(Response, levels = c("negative", "positive"))) - 1) %>%
group_by(Word,ConcValCombo) %>%
summarize(PropPositive = mean(Response.n),
MeanReactionTime = mean(ReactionTime))
## `summarise()` has grouped output by 'Word'. You can override using the
## `.groups` argument.
ggplot(agr, aes(x = MeanReactionTime, y = PropPositive)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "red") +
geom_text(aes(label = Word, color = ConcValCombo), vjust = -0.5, hjust = 1.5)
## `geom_smooth()` using formula = 'y ~ x'
# geom_text_repel(aes(label = Word, color = ConcValCombo),
# vjust = -0.5, hjust = 1.5) +
# scale_fill_manual(values=cbPalette) +
# scale_color_manual(values=cbPalette)
agr <- d %>%
filter(Task == "Animacy") %>%
mutate(Response.n = as.numeric(factor(Response, levels = c("inanimate", "animate"))) - 1) %>%
group_by(Word,Animacy,Valence) %>%
summarize(PropAnimate = mean(Response.n),
MeanReactionTime = mean(ReactionTime))
## `summarise()` has grouped output by 'Word', 'Animacy'. You can override using
## the `.groups` argument.
ggplot(agr, aes(x = MeanReactionTime, y = PropAnimate)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "red") +
geom_text(aes(label = Word, color = Valence), vjust = -0.5, hjust = 1.5)
## `geom_smooth()` using formula = 'y ~ x'
# geom_text_repel(aes(label = Word, color = ConcValCombo),
# vjust = -0.5, hjust = 1.5) +
# scale_fill_manual(values=cbPalette) +
# scale_color_manual(values=cbPalette)
agr <- d %>%
# filter(Task == "Concrete") %>%
# mutate(Response.n = as.numeric(factor(Response, levels = c("abstract", "concrete"))) - 1) %>%
group_by(Word,Task,Category) %>%
summarize(MeanAccuracy = mean(Accuracy),
MeanReactionTime = mean(ReactionTime))
## `summarise()` has grouped output by 'Word', 'Task'. You can override using the
## `.groups` argument.
ggplot(agr, aes(x = MeanReactionTime, y = MeanAccuracy)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "black") +
facet_wrap(~Task) +
geom_text(aes(label = Word, color = Category), vjust = -0.5, hjust = 1.5) +
guides(legend = "none")
## `geom_smooth()` using formula = 'y ~ x'
# theme(
# legend.position = "top", # Move legend to the top
# legend.title = element_text(size = 10), # Adjust legend title size
# legend.text = element_text(size = 9) # Adjust legend text size
# )
# geom_text_repel(aes(label = Word, color = ConcValCombo),
# vjust = -0.5, hjust = 1.5) +
# scale_fill_manual(values=cbPalette) +
# scale_color_manual(values=cbPalette)
# ggsave("../graphs/exp3_accXrt.pdf",width = 5, height = 3)
length(unique(d$ID.true))
## [1] 118
inacc.parts <- d %>%
group_by(ID.true,Task) %>%
summarise(MeanAccuracy = mean(Accuracy)) %>%
filter(MeanAccuracy < .75)
## `summarise()` has grouped output by 'ID.true'. You can override using the
## `.groups` argument.
# How many participants have Accuracy < .75?
length(unique(inacc.parts$ID.true))
## [1] 23
d.inaccurate.removed <- d %>%
anti_join(inacc.parts, by = "ID.true")
# Sanity check
length(unique(d.inaccurate.removed$ID.true))
## [1] 95
orig <- nrow(d.inaccurate.removed)
d.inaccurate.removed <- d.inaccurate.removed %>%
filter(Accuracy == 1)
nrow(d.inaccurate.removed)/orig*100
## [1] 94.05759
# Remove subjects with ReactionTime higher than 3x IQR
summary(d.inaccurate.removed$LogReactionTime)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.303 6.426 6.608 6.694 6.872 10.619
# Min. 1st Qu. Median Mean 3rd Qu. Max.
# 6.924 7.328 7.436 7.479 7.579 10.008
range(d.inaccurate.removed$LogReactionTime)
## [1] 2.302585 10.618714
hist(d.inaccurate.removed$LogReactionTime, breaks=100, col="lightblue", xlab="LogReactionTime (ms)",
main="Histogram with Normal Curve")
quantile(d.inaccurate.removed$LogReactionTime, na.rm = TRUE)
## 0% 25% 50% 75% 100%
## 2.302585 6.426488 6.608001 6.872128 10.618714
IQR(d.inaccurate.removed$LogReactionTime, na.rm = TRUE)*3 # 0.7526289
## [1] 1.336919
cutoff.high <- quantile(d.inaccurate.removed$LogReactionTime, na.rm = TRUE)[4] + IQR(d.inaccurate.removed$LogReactionTime, na.rm = TRUE)*3 # 8.419261
cutoff.low <- quantile(d.inaccurate.removed$LogReactionTime, na.rm = TRUE)[2] - IQR(d.inaccurate.removed$LogReactionTime, na.rm = TRUE)*3# 6.5088838.419261
# remove subjects with ReactionTime higher than 3 x IQR
df.outliers.removed <- subset(d.inaccurate.removed, (d.inaccurate.removed$LogReactionTime > cutoff.low) & (d.inaccurate.removed$LogReactionTime < cutoff.high))
hist(df.outliers.removed$LogReactionTime, breaks=100, col="lightblue", xlab="LogReactionTime (ms)",
main="Histogram with Normal Curve")
ggplot(df.outliers.removed, aes(x=LogReactionTime, fill=Task)) +
# facet_wrap(~BlockOrder) +
geom_density(alpha = .4)
ggplot(df.outliers.removed, aes(x=ReactionTime, fill=Task)) +
# facet_wrap(~BlockOrder) +
geom_density(alpha = .4)
agr <- d.inaccurate.removed %>%
group_by(Task,Category) %>%
summarize(MeanRT = mean(ReactionTime),
SD = sd(ReactionTime),
MeanLogRT = mean(LogReactionTime))
## `summarise()` has grouped output by 'Task'. You can override using the
## `.groups` argument.
print(agr)
## # A tibble: 7 × 5
## # Groups: Task [3]
## Task Category MeanRT SD MeanLogRT
## <chr> <chr> <dbl> <dbl> <dbl>
## 1 Animacy Nouns 831. 483. 6.63
## 2 Concrete Adjs 1012. 667. 6.81
## 3 Concrete Nouns 934. 631. 6.74
## 4 Concrete Verbs 1071. 1091. 6.85
## 5 Valence Adjs 780. 350. 6.60
## 6 Valence Nouns 834. 669. 6.63
## 7 Valence Verbs 866. 406. 6.69
agr <- df.outliers.removed %>%
group_by(Task,Word) %>%
summarize(MeanLogReactionTime = mean(LogReactionTime),
CILow = ci.low(LogReactionTime),
CIHigh = ci.high(LogReactionTime)) %>%
mutate(YMin = MeanLogReactionTime - CILow,
YMax = MeanLogReactionTime + CIHigh)
## `summarise()` has grouped output by 'Task'. You can override using the
## `.groups` argument.
ggplot(agr, aes(x=MeanLogReactionTime, fill=Task)) +
geom_density(alpha = .4)
ggplot(agr, aes(x=Task, y=MeanLogReactionTime,fill=Task)) +
geom_violin(trim=FALSE,alpha=.4) +
geom_jitter(shape=16, position=position_jitter(0.2)) +
# geom_errorbar(aes(ymin=YMin,ymax=YMax),width=.25,position="dodge", show.legend = FALSE) +
# theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
guides(fill = "none")
agr <- df.outliers.removed %>%
group_by(Task,Word) %>%
summarize(MeanReactionTime = mean(ReactionTime),
CILow = ci.low(ReactionTime),
CIHigh = ci.high(ReactionTime)) %>%
mutate(YMin = MeanReactionTime - CILow,
YMax = MeanReactionTime + CIHigh)
## `summarise()` has grouped output by 'Task'. You can override using the
## `.groups` argument.
ggplot(agr, aes(x=MeanReactionTime, fill=Task)) +
geom_density(alpha = .4)
ggplot(agr, aes(x=Task, y=MeanReactionTime,fill=Task)) +
geom_violin(trim=FALSE,alpha=.4) +
geom_jitter(shape=16, position=position_jitter(0.2)) +
# geom_errorbar(aes(ymin=YMin,ymax=YMax),width=.25,position="dodge", show.legend = FALSE) +
# theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
guides(fill = "none")
# ggsave("../graphs/total_rt_violin.pdf",width = 4, height = 3)
agr <- df.outliers.removed %>%
group_by(Task,Category) %>%
reframe(MeanReactionTime = mean(ReactionTime),
CILow = ci.low(ReactionTime),
CIHigh = ci.high(ReactionTime)) %>%
mutate(YMin = MeanReactionTime - CILow,
YMax = MeanReactionTime + CIHigh)
dodge = position_dodge(.9)
ggplot(data=agr, aes(x=reorder(Category,MeanReactionTime),y=MeanReactionTime,fill=Task)) +
geom_bar(position=dodge,stat="identity") +
# facet_wrap(~Task) +
geom_errorbar(aes(ymin=YMin,ymax=YMax),width=.25,position=position_dodge(0.9)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
# guides(fill = "none")
agr <- df.outliers.removed %>%
group_by(Task,Category) %>%
reframe(MeanReactionTime = mean(ReactionTime),
CILow = ci.low(ReactionTime),
CIHigh = ci.high(ReactionTime)) %>%
mutate(YMin = MeanReactionTime - CILow,
YMax = MeanReactionTime + CIHigh)
ggplot(agr, aes(x=Category, y=MeanReactionTime,fill=Task)) +
geom_violin(trim=FALSE,alpha=.4) +
geom_jitter(shape=16, position=position_jitter(0.2)) +
guides(fill = "none")
## Warning: Groups with fewer than two datapoints have been dropped.
## ℹ Set `drop = FALSE` to consider such groups for position adjustment purposes.
## Groups with fewer than two datapoints have been dropped.
## ℹ Set `drop = FALSE` to consider such groups for position adjustment purposes.
## Groups with fewer than two datapoints have been dropped.
## ℹ Set `drop = FALSE` to consider such groups for position adjustment purposes.
## Groups with fewer than two datapoints have been dropped.
## ℹ Set `drop = FALSE` to consider such groups for position adjustment purposes.
## Groups with fewer than two datapoints have been dropped.
## ℹ Set `drop = FALSE` to consider such groups for position adjustment purposes.
## Groups with fewer than two datapoints have been dropped.
## ℹ Set `drop = FALSE` to consider such groups for position adjustment purposes.
## Groups with fewer than two datapoints have been dropped.
## ℹ Set `drop = FALSE` to consider such groups for position adjustment purposes.
## Warning in max(data$density, na.rm = TRUE): no non-missing arguments to max;
## returning -Inf
## Warning: Computation failed in `stat_ydensity()`.
## Caused by error in `$<-.data.frame`:
## ! replacement has 1 row, data has 0
test <- df.outliers.removed %>%
# filter(Task %in% c("Concrete", "Valence")) %>% # Keep only relevant tasks
group_by(Word, Task) %>%
summarise(
RT = mean(ReactionTime, na.rm = TRUE), # Take the mean RT if duplicates exist
.groups = "drop_last" # Drop grouping by Task but keep Word and ID.true
) %>%
pivot_wider(names_from = Task, values_from = RT, names_prefix = "RT_") %>% # Reshape to wide format
filter((RT_Concrete <= RT_Valence) | (RT_Animacy <= RT_Valence)) %>% # Apply the condition
pivot_longer(
cols = starts_with("RT_"), # Select the reshaped columns
names_to = "Task", # Restore Task column
names_prefix = "RT_", # Remove "RT_" prefix to match original Task names
values_to = "ReactionTime" # Column for the RT values
) %>%
ungroup()
nrow(test)/nrow(df.outliers.removed)
## [1] 0.005041311
agr <- test %>%
group_by(Word, Task) %>%
summarize(MeanReactionTime = mean(ReactionTime),
CILow = ci.low(ReactionTime),
CIHigh = ci.high(ReactionTime)) %>%
mutate(YMin = MeanReactionTime - CILow,
YMax = MeanReactionTime + CIHigh)
## `summarise()` has grouped output by 'Word'. You can override using the
## `.groups` argument.
dodge = position_dodge(.9)
ggplot(data=agr, aes(x=Task,y=MeanReactionTime,fill=Task)) +
geom_bar(position=dodge,stat="identity") +
facet_wrap(~Word) +
geom_errorbar(aes(ymin=YMin,ymax=YMax),width=.25,position=position_dodge(0.9)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
## Warning: Removed 29 rows containing missing values or values outside the scale range
## (`geom_bar()`).
# guides(fill = "none")
test_avv <- d %>%
filter(Word %in% test$Word) %>%
group_by(Word, Task) %>%
summarize(MeanAccuracy = mean(Accuracy),
CILow = ci.low(Accuracy),
CIHigh = ci.high(Accuracy),
) %>%
mutate(YMin = MeanAccuracy - CILow,
YMax = MeanAccuracy + CIHigh)
## `summarise()` has grouped output by 'Word'. You can override using the
## `.groups` argument.
# View(test_avv)
dodge = position_dodge(.9)
ggplot(data=test_avv, aes(x=Task,y=MeanAccuracy,fill=Task)) +
geom_bar(position=dodge,stat="identity") +
facet_wrap(~Word) +
geom_errorbar(aes(ymin=YMin,ymax=YMax),width=.25,position=position_dodge(0.9)) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
# guides(fill = "none")
test_avv <- d %>%
filter(Word %in% test$Word) %>%
group_by(Word, Task) %>%
summarize(MeanAccuracy = mean(Accuracy),
MeanReactionTime = mean(ReactionTime))
## `summarise()` has grouped output by 'Word'. You can override using the
## `.groups` argument.
ggplot(test_avv, aes(x = MeanReactionTime, y = MeanAccuracy)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE, color = "red") +
# geom_text(aes(label = Word, color = Task), vjust = -0.5, hjust = 1.5)
geom_text_repel(aes(label = Word, color = Task),
vjust = -0.5, hjust = 1.5) +
scale_fill_manual(values=cbPalette) +
scale_color_manual(values=cbPalette)
## `geom_smooth()` using formula = 'y ~ x'
## Warning: ggrepel: 36 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps
convert everything to factors
Yes
m = lmer(LogReactionTime ~ Task + (1|ID.true) + (1|Word), data=center)
summary(m)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: LogReactionTime ~ Task + (1 | ID.true) + (1 | Word)
## Data: center
##
## REML criterion at convergence: 9878.4
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.4568 -0.6512 -0.1716 0.4472 5.3564
##
## Random effects:
## Groups Name Variance Std.Dev.
## Word (Intercept) 0.002692 0.05189
## ID.true (Intercept) 0.032749 0.18097
## Residual 0.089738 0.29956
## Number of obs: 21423, groups: Word, 226; ID.true, 95
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 6.672e+00 2.086e-02 1.450e+02 319.815 < 2e-16 ***
## TaskConcrete 9.314e-02 1.032e-02 2.105e+04 9.021 < 2e-16 ***
## TaskValence -4.412e-02 9.279e-03 2.116e+04 -4.755 1.99e-06 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) TskCnc
## TaskConcret -0.399
## TaskValence -0.402 0.897
table(center$Category)
##
## Adjs Nouns Verbs
## 5340 11815 4268
m = lmer(LogReactionTime ~ Category + (1|ID.true) + (1|Word), data=center)
summary(m)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: LogReactionTime ~ Category + (1 | ID.true) + (1 | Word)
## Data: center
##
## REML criterion at convergence: 10771.5
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.1545 -0.6492 -0.1881 0.4500 5.2729
##
## Random effects:
## Groups Name Variance Std.Dev.
## Word (Intercept) 0.002583 0.05082
## ID.true (Intercept) 0.033085 0.18189
## Residual 0.093664 0.30605
## Number of obs: 21423, groups: Word, 226; ID.true, 95
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 6.68979 0.03781 96.26099 176.917 <2e-16 ***
## CategoryNouns -0.02990 0.04579 96.91688 -0.653 0.515
## CategoryVerbs 0.06257 0.05702 97.15462 1.097 0.275
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) CtgryN
## CategoryNns -0.826
## CategryVrbs -0.663 0.549
m = lmer(LogReactionTime ~ Task*Category + (1|ID.true) + (1|Word), data=center)
## fixed-effect model matrix is rank deficient so dropping 2 columns / coefficients
summary(m)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: LogReactionTime ~ Task * Category + (1 | ID.true) + (1 | Word)
## Data: center
##
## REML criterion at convergence: 9808.1
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.4766 -0.6492 -0.1704 0.4463 5.3271
##
## Random effects:
## Groups Name Variance Std.Dev.
## Word (Intercept) 0.002679 0.05175
## ID.true (Intercept) 0.032848 0.18124
## Residual 0.089362 0.29893
## Number of obs: 21423, groups: Word, 226; ID.true, 95
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 6.642e+00 3.901e-02 1.106e+02 170.271 < 2e-16
## TaskConcrete 1.513e-01 1.239e-02 2.127e+04 12.204 < 2e-16
## TaskValence -4.425e-02 9.268e-03 2.121e+04 -4.774 1.82e-06
## CategoryNouns 2.510e-02 4.589e-02 9.925e+01 0.547 0.586
## CategoryVerbs 8.471e-02 5.714e-02 9.951e+01 1.482 0.141
## TaskConcrete:CategoryNouns -1.018e-01 1.070e-02 2.124e+04 -9.519 < 2e-16
## TaskConcrete:CategoryVerbs -5.250e-02 1.231e-02 2.116e+04 -4.264 2.02e-05
##
## (Intercept) ***
## TaskConcrete ***
## TaskValence ***
## CategoryNouns
## CategoryVerbs
## TaskConcrete:CategoryNouns ***
## TaskConcrete:CategoryVerbs ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) TskCnc TskVln CtgryN CtgryV TsC:CN
## TaskConcret -0.244
## TaskValence -0.238 0.748
## CategoryNns -0.810 0.083 0.035
## CategryVrbs -0.644 0.045 0.000 0.549
## TskCncrt:CN 0.078 -0.513 -0.003 -0.096 -0.052
## TskCncrt:CV 0.067 -0.444 0.000 -0.057 -0.104 0.514
## fit warnings:
## fixed-effect model matrix is rank deficient so dropping 2 columns / coefficients